package cn.dengta.webapp.trade.entity;

import java.util.Date;
import java.util.List;

import cn.dengta.common.model.BizFlag;
import cn.dengta.webapp.base.entity.BizEntity;
import cn.dengta.webapp.trade.model.UserLimitBizType;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.X;
import org.apache.commons.lang3.tuple.Pair;

/**
 * @author lgy
 * @since 2022-06-16
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("dt_user_limit")
public class UserLimit extends BizEntity implements BizFlag.WritableBizFlag {

	/** 用户id */
	private Long userId;
	/** 开始日期 */
	private Date startDate;
	/** 类型：0=提现；1=VIP列表黑名单... */
	private Integer type;
	/** 业务标记 */
	private Long bizFlag;
	/** 结束日期 */
	private Date endDate;
	/** 备注 */
	private String remark;

	public UserLimit init(Date now, Integer type, Integer status) {
		initTime(now);
		this.type = type;
		this.status = status;
		this.startDate = now;
		this.bizFlag = 0L;
		return this;
	}

	public void addBizFlag(List<Pair<UserLimitBizType, Boolean>> flag) {
		if (X.isValid(flag)) {
			this.bizFlag = this.bizFlag == null ? 0L : this.bizFlag;
			for (Pair<UserLimitBizType, Boolean> pair : flag) {
				this.toggleFlag(pair.getLeft().flag, pair.getRight());
			}
		}
	}

	@Override
	public long getBizFlag() {
		return bizFlag;
	}

	@Override
	public void setBizFlag(long l) {
		this.bizFlag = l;
	}

	public static final String USER_ID = "user_id";
	public static final String START_DATE = "start_date";
	public static final String TYPE = "type";
	public static final String BIZ_FLAG = "biz_flag";
	public static final String STATUS = "status";
	public static final String STATE = "state";
	public static final String END_DATE = "end_date";
	public static final String REMARK = "remark";

}
